package cn.edu.scau.cmi.linpeiwei.controller;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;

import javafx.scene.text.Text;

import javafx.scene.control.TextField;

import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.linpeiwei.domain.AutoInsurance;
import cn.edu.scau.cmi.linpeiwei.domain.BodyInjur;
import cn.edu.scau.cmi.linpeiwei.domain.Collision;
import cn.edu.scau.cmi.linpeiwei.domain.Com;
import cn.edu.scau.cmi.linpeiwei.domain.Other;
import cn.edu.scau.cmi.linpeiwei.domain.PersonInjur;
import cn.edu.scau.cmi.linpeiwei.domain.Property;
import cn.edu.scau.cmi.linpeiwei.factory.BodyPolicy;
import cn.edu.scau.cmi.linpeiwei.factory.CollPolicy;
import cn.edu.scau.cmi.linpeiwei.factory.ComPolicy;
import cn.edu.scau.cmi.linpeiwei.factory.OtherPolicy;
import cn.edu.scau.cmi.linpeiwei.factory.PersonPolicy;
import cn.edu.scau.cmi.linpeiwei.factory.PolicyProducer;
import cn.edu.scau.cmi.linpeiwei.factory.PropPolicy;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.control.ChoiceBox;

public class FactoryController extends AnchorPane implements Initializable{
	@FXML
	private ChoiceBox choiceBox;
	@FXML
	private Button infoButton;
	@FXML
	private ImageView imageView;
	@FXML
	private TextField textFieldName;
	@FXML
	private TextField textFieldNum;
	@FXML
	private Text textInfo;
	private Image image;
	private PolicyProducer policyProducer = null;
	final String Info[] = {"人身伤亡", "碰撞", "驾驶员本身伤亡", "财产损失", "综合保险", "其他"};

	// Event Listener on Button[#infoButton].onAction
	@FXML
	public void eventButton(ActionEvent event) {
		// TODO Autogenerated
		textInfo.setText("姓名：" + textFieldName.getText() + '\n' + "学号：" + textFieldNum.getText() + '\n' + "保险类型：" + policyProducer.getInsurObj().getInsurInfo());
	}

	@Override
	public void initialize(URL arg0, ResourceBundle arg1) {
		image = new Image("/cn/edu/scau/cmi/linpeiwei/view/0703213803.jpg");
		imageView.setImage(image);
		choiceBox.getItems().addAll(FXCollections.observableArrayList(Info));
		//choiceBox.getSelectionModel().selectFirst();
		choiceBox.getSelectionModel().selectedIndexProperty().addListener((ov,oldv,newv)->{
			policyProducer = getPolicyProducer(Info[newv.intValue()]);
			infoButton.setDisable(false);
			
		});
		
	}
	private PolicyProducer getPolicyProducer(String insurType) {

		switch (insurType) {
		case "人身伤亡":
			return new BodyPolicy();

		case "碰撞":
			return new CollPolicy();
			
		case "驾驶员本身伤亡":
			return new PersonPolicy();
			
		case "财产损失":
			return new PropPolicy();
			
		case "综合保险":
			return new ComPolicy();
			
		default:
			return new OtherPolicy();
			
		}
		
	}
}
